﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LSQL;

namespace Shopfloormanagement.PDCA
{
	public partial class methodSwitch: DevExpress.XtraEditors.XtraForm
	{
        public methodSwitch()
		{
            instance = this;
            InitializeComponent();
		}

        public static methodSwitch instance = new methodSwitch();
        public static string Problem;

        private void btnA3_Click(object sender, EventArgs e)
        {
            this.Close();
            //进入A3那个步骤
            Form_Department.btn_PdcaMark_Click();
        }

        private void btnPDCA_Click(object sender, EventArgs e)
        {
            PDCA.departmentID = Form_Department.DepartmentID;
            DataTable dt = SQL.ReturnDataTableDist(SystemInfo.sys, "Codename", "Factories", $"ID = {SystemInfo.readFactory}");
            string code = dt.Rows[0]["Codename"].ToString();
            string datetime = DateTime.Now.ToString("yyMMdd");
            string condition = $"select count(*) as count from PDCA_View where DepartmentID = {SystemInfo.readparentDep}";

            DataTable dtCount = SQL.ReturnDataTable(SystemInfo.SQL, condition);
            int aa = (int)dtCount.Rows[0]["count"] + 1;
            string a3count;
            if (aa < 10)
            {
                a3count = $"0{aa}";
            }
            else
            {
                a3count = aa.ToString();
            }
            Problem = Form_Department.topicStr;
            string PDCAcode = code + datetime + a3count;
            PDCA.pdcaNumber = PDCAcode;
            PDCA.isNewPDCA = true;
            PDCA pdca = new PDCA();
            pdca.txtDescription.Text = Problem;
            pdca.ShowDialog();
        }
    }
}